# This code is hosted on http://code.google.com/p/lenthorp/
# Freely available for use in applications, but should NOT be modified
# Email all comments to lenthorpresearch@gmail.com

from math import sqrt
from numpy import dot
import numpy as np
##MQ radial basis funcion
## phi(|x - xc|) = sqrt(1+ (x-xc)^2 c^2)
##

def MQ(x,xc,c,derivative=0,direction = 0):
    tmp =  dot(np.array(x)-np.array(xc),np.array(x)-np.array(xc))
    c2 = c*c
    stmp = sqrt(c2 + tmp )
    if(derivative == 0) :
        return stmp
    elif (derivative == 1) :
        return (x[direction] - xc[direction])/stmp
    elif (derivative == 2):
        return 1/stmp - ((x[direction] - xc[direction]))**2/(stmp)**3
    else:
        return 0.0
